"use strict";

// 引入koa
import Koa from "koa";

// 引入跨域
import cors from "koa2-cors";

// koaBody
import koaBody from "koa-body";
// 引入配置文件

import config from "./config/index.js";

// 引入汇总路由

import RouterInit from "@/router/RouterInit";

// 实例koa服务
const Engine=new Koa();
// 跨域处理
Engine.use(cors({
    origin:"*",
    allowedMethods:["GET","POST"]
}));
// 处理网络请求
Engine.use(koaBody());

// 测试请求时间
Engine.use(async (ctx,next)=>{
    console.time(`enter the server in the ${ctx.url} and leave with`);
    await next();
    console.timeEnd(`enter the server in the ${ctx.url} and leave with`);
});
// 挂载汇总路由
Engine.use(RouterInit.routes());

Engine.on("error",(error) => {
    console.error(error);
});

// 监听服务端口
Engine.listen(config.serve_port);
